package org.lee.springcloud.gateway;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.gateway.filter.GatewayFilterChain;
import org.springframework.cloud.gateway.filter.GlobalFilter;
import org.springframework.cloud.gateway.route.RouteLocator;
import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder;
import org.springframework.context.annotation.Bean;
import reactor.core.publisher.Mono;

/**
 * @author jackielee
 * @version 1.0
 * @description GateWayApplication
 * @date 2021/3/15
 */
@SpringBootApplication
public class GateWayEurekaApplication {
  private final Logger logger = LoggerFactory.getLogger(GateWayEurekaApplication.class);
  public static void main(String[] args) {
    SpringApplication.run(GateWayEurekaApplication.class, args);
  }

  @Bean
  public GlobalFilter customerFilter(){
    return (exchange, chain)->{
      logger.info("filter the first...");
      return chain.filter(exchange).then(Mono.fromRunnable(()->{
        logger.info("first filter post");
      }));
    };
  }

//  /**
//   * 通过@Bean配置一个/about路径
//   *
//   * @param builder
//   * @return
//   */
//  @Bean
//  public RouteLocator customRouteLocator(RouteLocatorBuilder builder) {
//    return builder
//        .routes()
//        .route("about-route", r -> r.path("/about").uri("http://www.ityouknow.com"))
//        .route("consul-provider", r -> r.path("/hello").uri("http://localhost:8503"))
//        .route("balance_addparam", r->r.method("get").filters(f->f.addRequestParameter("foo","blbar")).uri("lb://spring-cloud-producer"))
//        .build();
//  }
}
